﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Pages_Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {


    }
    protected void CreateUserWizard_CreatingUser(object sender, LoginCancelEventArgs e)
    {

        var msg = (Label)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CaptchaErrorMessage");
        var recaptcha = (Recaptcha.RecaptchaControl)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("RecaptchaControl");

        if (null == recaptcha)
        {
            e.Cancel = true;
            return;
        }
        ////First, check if CAPTCHA matches up
        recaptcha.Validate();
        if (!recaptcha.IsValid)
        {
            //CAPTCHA invalid
            msg.Text = "Codul introdus nu se potriveste cu imaginea furnizate, vă rugăm să încercaţi din nou cu aceasta noua imagine.";
            e.Cancel = true;
        }
        else
        {
            e.Cancel = false;
        }
    }
    protected void CreateUserWizard_CreatedUser(object sender, EventArgs e)
    {
        Roles.AddUserToRole(CreateUserWizard.UserName, "User");
        // Create an empty Profile for the newly created user
        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard.UserName, true);

        // Populate some Profile properties off of the create user wizard
        p.FirstName = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;
        p.LastName = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("LastName")).Text;
        p.Address = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("Adresa")).Text;
        p.Judet = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("Judet")).Text;
        p.Oras = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("Oras")).Text;
        p.CodPostal = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CodPostal")).Text;
        p.TelefonMobil = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("TelefonMobil")).Text;
        p.TelefonFix = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("TelefonFix")).Text;
        p.CNP = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CNP")).Text;
        p.SerieSiNumar = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("Serie")).Text;
        p.EliberatDe = ((TextBox)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("EliberatDe")).Text;
        p.Cetatenie = ((DropDownList)CreateUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("Cetatenie")).SelectedValue;

        // Save the profile - must be done since we explicitly created this profile instance
        p.Save();
    }
    protected void ContinueButton_Click(object sender, EventArgs e)
    {
        Response.RedirectToRoute("Home");
    }
}